const AudioUtil  = {
  innerAudioContext: null,

  play(src, mixWithOther) {
    AudioUtil.stop()
    AudioUtil.innerAudioContext = wx.createInnerAudioContext()
    AudioUtil.innerAudioContext.autoplay = false // 不自动播放
    AudioUtil.innerAudioContext.src = src // 音频的地址
    AudioUtil.innerAudioContext.mixWithOther = mixWithOther ? true : false
    AudioUtil.innerAudioContext.obeyMuteSwitch = false // 即使用户打开了静音开关，也能继续发出声音
    AudioUtil.innerAudioContext.play()
  },

  pause() {
    if (AudioUtil.innerAudioContext) {
      AudioUtil.innerAudioContext.pause()
    }
  },

  seek(position) {
    if (AudioUtil.innerAudioContext) {
      AudioUtil.innerAudioContext.seek(position)
    }
  },

  stop() {
    if (AudioUtil.innerAudioContext) {
      AudioUtil.innerAudioContext.stop()
      AudioUtil.innerAudioContext.destroy()
    }
    AudioUtil.innerAudioContext = null
  },
  
}
export default AudioUtil